function onloadJS() {
    
/*
*автоподгрузчик специальностей
**/
//$("#vacancySpeciality").autocomplete(W_JS + "vacancySpeciality.php", {
//    delay:10,
//    minChars:1,
//    matchSubset:1,
//    autoFill:true,
//    matchContains:1,
//    cacheLength:10,
//    selectFirst:true,
//    maxItemsToShow:10
//});
//

/*
*автоподгрузчик городов
**/
$("#city").autocomplete(W_AJAX + "city/getCity.php", {
    delay:10,
    minChars:1,
    matchSubset:1,
    autoFill:true,
    matchContains:1,
    cacheLength:10,
    selectFirst:true,
    maxItemsToShow:10
});
    

$(function() {
    $( "#slider-salary" ).slider({
        range: true,
        min: 8000,
        max: 150000,
        values: [ 8000, 40000 ],
        step : 1000,
        slide: function( event, ui ) {
            handlerSalarySlider( event,ui);
        }
    });
}); 


$(function() {
    $( "#slider-age" ).slider({
        range: true,
        min: 16,
        max: 100,
        values: [ 16, 40 ],
        step : 1,
        slide: function( event, ui ) {
            handlerAgeSlider( event,ui);
        }
    });
}); 


$(function() {
    $( "#slider-experience").slider({
    min: -1,
    max: 20,
    values: [ 1 ],
    slide: function( event, ui ) {
           handlerExperienceSlider( event,ui);
        }
    });
}); 



$("#tarea_cr").markItUp(myBbcodeSettings);
$("#fulltarea_cr").markItUp(myBbcodeSettings);
$("#tarea_cr2").markItUp(myBbcodeSettings);
//$("#dialog:ui-dialog").dialog("destroy"); 

}

function addVacancy() {
     var VacancyInfo = {};

     VacancyInfo.name = document.getElementById('name').value;
    
    VacancyInfo.currency = document.getElementById("currency").value;
    
    VacancyInfo.salaryFrom = $( "#slider-salary" ).slider( "values", 0 );
    
    VacancyInfo.salaryUnder = $( "#slider-salary" ).slider( "values", 1 );
    
    VacancyInfo.ageFrom = $( "#slider-age" ).slider( "values", 0 );
    
    VacancyInfo.ageUnder = $( "#slider-age" ).slider( "values", 1 );
    
    VacancyInfo.experienceFrom = $( "#slider-experience" ).slider( "values", 0 );
    
    VacancyInfo.description = document.getElementById("tarea_cr").value;
    
    VacancyInfo.requirement = document.getElementById("fulltarea_cr").value;
    
    VacancyInfo.conditions = document.getElementById("tarea_cr2").value;
    
    VacancyInfo.idContactUser = document.getElementById("idContactUser").value;
    
    VacancyInfo.contactInfo = document.getElementById("contactInfo").value;
    
    VacancyInfo.sex = document.getElementById("sex").value;
    
    VacancyInfo.regime = document.getElementById("regime").value;
    
    VacancyInfo.type = document.getElementById("type").value;
    
    //console.log(VacancyInfo);
    
    
     //кусок кода для вычленения get параметров(стыбрин с инета)   
    var tmp = new Array();      // два вспомагательных
    var tmp2 = new Array();     // массива
    var param = new Array();
     
    var get = location.search;  // строка GET запроса
    if(get != '') {
        tmp = (get.substr(1)).split('&');   // разделяем переменные
        
        for(var i=0; i < tmp.length; i++) {
        
        
        tmp2 = tmp[i].split('=');       // массив param будет содержать
        param[tmp2[0]] = tmp2[1];       // пары ключ(имя переменной)->значение
        }
    }
  
    for (var key in param) {
        //console.log(key + '=>' + param[key]);
    }
    
    VacancyInfo.idFirm = param['id'];
    
    /*
     *пока остального ничего нет, то присваиваем тестовое значения
     *
     **/
    
    VacancyInfo.idFirm = 1;
    
     var  dataSend = {
            query: 'addVacancyFixedFirm',
            vacancyInfo : VacancyInfo
        }
        

        $.post(
            W_AJAX + "controllers/controllerCompany.php",
            {
                dataSend : dataSend
            },
            function(data){
                if (data.status == "true")
                   alert ('Вакансия добавлена');
                else
                   alert(data.error);
            },
            'json'
        );
}



function updateSalary(fromPage) {

    var flagError = false;
    var salaryFrom = document.getElementById('salaryRateFrom').value;
    var salaryUnder = document.getElementById('salaryRateUnder').value;

    console.log("1");

    salaryFrom = parseInt(salaryFrom);
    salaryUnder = parseInt(salaryUnder);
    console.log("2");

    //если указанная зп меньше 8000
    if (salaryFrom < 8000){
        alert("Нельзя людям так мало платить, жмот");
        document.getElementById('salaryRateFrom').value = 8000;
        salaryFrom = 8000;
        console.log("3");
    }

    if (salaryFrom > 10000000){
        alert("Вы слишком щедры со своими работниками");
        document.getElementById('salaryRateFrom').value = 8000;
        salaryFrom = 8000;
        console.log("4");
    }

    if (salaryUnder > 10000000){
        alert("Вы слишком щедры со своими работниками");
        document.getElementById('salaryRateUnder').value = 10000000;
        salaryUnder = 10000000;
        console.log("5");
    }

    if (Math.abs (salaryFrom - salaryUnder) < 1000){
        salaryUnder = salaryFrom + 2000;
        document.getElementById('salaryRateUnder').value = salaryUnder;
        console.log("6");
    }

    var salaryMinSlider = $( "#slider-salary" ).slider("option", "min");
    var salaryMaxSlider = $( "#slider-salary" ).slider("option", "max");

    if (salaryFrom < salaryMinSlider){
    salaryMinSlider = salaryFrom; 
    console.log(7);
    }

    if (salaryFrom > salaryUnder){
        var x = salaryFrom;
        salaryFrom = salaryUnder;
        salaryUnder = x;
    }



    console.log("salaryUnder" + salaryUnder);
    console.log("salaryMaxSlider" + salaryMaxSlider);
    if (salaryUnder > salaryMaxSlider){
    salaryMaxSlider = salaryUnder; 
    console.log(8);
    }

    $( "#slider-salary" ).slider("destroy");
    $( "#slider-salary" ).slider({
        range: true,
        min: salaryMinSlider,
        max: salaryMaxSlider,
        values: [ salaryFrom, salaryUnder],
        step : 1000,
        slide: function( event, ui ) {
            handlerSalarySlider( event,ui);
        }
    });
}

function updateSalaryFrom() {
    var salaryFrom = document.getElementById('salaryRateFrom').value;
    var salaryUnder = document.getElementById('salaryRateUnder').value;
}

function handlerSalarySlider(event, ui) {
    
    var salaryFrom = $( "#slider-salary" ).slider( "values", 0 );
    var salaryUnder = $( "#slider-salary" ).slider( "values", 1 );

    document.getElementById("salaryRateFrom").value = salaryFrom;
    document.getElementById("salaryRateUnder").value = salaryUnder;
}



//******************************************************************************

/*
*
*
*/
function updateAge(fromPage) {

    var flagError = false;
    var ageFrom = document.getElementById('ageRateFrom').value;
    var ageUnder = document.getElementById('ageRateUnder').value;
    console.log("1");


    ageFrom = parseInt(ageFrom);
    ageUnder = parseInt(ageUnder);
    console.log("2");

    //если указанная зп меньше 8000
    if (ageFrom < 16){
        alert("Нельзя малолеток брать на работу");
        document.getElementById('ageRateFrom').value = 16;
        ageFrom = 16;
        console.log("3");
    }

    if (ageFrom > 100){
        alert("Не стоит брать столь старых работников к себе на работу");
        document.getElementById('ageRateFrom').value = 100;
        ageFrom = 18;
        console.log("4");
    }

    if (ageUnder > 100){
        alert("Не стоит брать столь старых работников к себе на работу");
        document.getElementById('ageRateUnder').value = 100;
        ageUnder = 100;
        console.log("5");
    }

    if (Math.abs (ageFrom - ageUnder) < 1){
        ageUnder = ageFrom + 2;
        document.getElementById('ageRateUnder').value = ageUnder;
        console.log("6");
    }

    var ageMinSlider = $( "#slider-age" ).slider("option", "min");
    var ageMaxSlider = $( "#slider-age" ).slider("option", "max");

    if (ageFrom < ageMinSlider){
        ageMinSlider = ageFrom; 
        console.log(7);
    }

    if (ageFrom > ageUnder){
        var x = ageFrom;
        ageFrom = ageUnder;
        ageUnder = x;
    }



    console.log("ageUnder" + ageUnder);
    console.log("ageMaxSlider" + ageMaxSlider);
    if (ageUnder > ageMaxSlider){
    ageMaxSlider = ageUnder; 
    console.log(8);
    }

    $( "#slider-age" ).slider("destroy");
    $( "#slider-age" ).slider({
        range: true,
        min: ageMinSlider,
        max: ageMaxSlider,
        values: [ ageFrom, ageUnder],
        step : 1,
        slide: function( event, ui ) {
            handlerAgeSlider( event,ui);
        }
    });
}

function updateAgeFrom() {
    var ageFrom = document.getElementById('ageRateFrom').value;
    var ageUnder = document.getElementById('ageRateUnder').value;
}

function handlerAgeSlider(event, ui){
    
    var ageFrom = $( "#slider-age" ).slider( "values", 0 );
    var ageUnder = $( "#slider-age" ).slider( "values", 1 );

    document.getElementById("ageRateFrom").value = ageFrom;
    document.getElementById("ageRateUnder").value = ageUnder;
}



//опыт работы
//******************************************************************************

/*
*
*
*/
function updateExperience(fromPage) {

    var flagError = false;
    var experienceFrom = document.getElementById('experienceRateFrom').value;
    
    if (experienceFrom == 'undefind'){
        flagError = true;
        alert("asd");
    }
        
    console.log("1");

    experienceFrom = parseInt(experienceFrom);
    
    console.log("2");
    
    //если указанная зп меньше 8000
    if (experienceFrom < 0 && !flagError){
        alert("???");
        document.getElementById('experienceRateFrom').value = 0;
        experienceFrom = 0;
        console.log("3");
    }

    if (experienceFrom > 20 && !flagError){
        alert("слишком опытный");
        document.getElementById('experienceRateFrom').value = 20;
        experienceFrom = 18;
        console.log("4");
    }

    var experienceMinSlider = $( "#slider-experience" ).slider("option", "min");
    var experienceMaxSlider = $( "#slider-experience" ).slider("option", "max");

    if (experienceFrom < experienceMinSlider && !flagError){
        experienceMinSlider = experienceFrom; 
        console.log(7);
    }

    
    console.log("experienceFrom" + experienceMaxSlider);
    console.log("experienceMinSlider" + experienceMaxSlider);
    console.log("experienceMaxSlider" + experienceMaxSlider);

    if (!flagError){
        $( "#slider-experience" ).slider("destroy");
        $( "#slider-experience" ).slider({
            min: experienceMinSlider,
            max: experienceMaxSlider,
            values: [ experienceFrom ],
            step : 1,
            slide: function( event, ui ) {
                handlerExperienceSlider( event,ui);
            }
        });
    }
}

function updateExperienceFrom() {
    var experienceFrom = document.getElementById('experienceRateFrom').value;
}

function handlerExperienceSlider(event, ui){
    
    console.log("here");
    var experienceFrom = $( "#slider-experience" ).slider( "values", 0 );

    document.getElementById("experienceRateFrom").value = experienceFrom;
}

function getParticipants(){
    var idFirm = document.getElementById("branch").value;
        
    var  dataSend = {
                 query: 'getListPostParticipants',
                 idFirm : idFirm
        }
        
        $.post(
            W_AJAX + "controllers/controllerCompany.php",
            {
                dataSend : dataSend
            },
            function(data){
                var serverAnswer = data;
                    $('#contactUser').innerHTML='';
                    document.getElementById('contactUser').innerHTML = serverAnswer;
                },
            'text'
        ); 
}

//*****************************************************************************

function tideVacancy(){
    
    var text = document.getElementById("name").value;
    if (text == "Название вакансии"){
        document.getElementById("name").value='';
    }  
}

function recoverVacancy(){
    
    var text = document.getElementById("name").value;
    if (text == ""){
        document.getElementById("name").value='Название вакансии';
    }  
}

//**
function tideContactPerson(){
    var text = document.getElementById("contactInfo").value;
    if (text == "Контактная персона"){
        document.getElementById("contactInfo").value='';
    }  
}

function recoverContactPerson(){
    var text = document.getElementById("contactInfo").value;
    if (text == ""){
        document.getElementById("contactInfo").value='Контактная персона';
    }  
}

function updateSalary(fromPage) {

    var flagError = false;
    var salaryFrom = document.getElementById('salaryRateFrom').value;
    var salaryUnder = document.getElementById('salaryRateUnder').value;

    console.log("1");

    salaryFrom = parseInt(salaryFrom);
    salaryUnder = parseInt(salaryUnder);
    console.log("2");

    //если указанная зп меньше 8000
    if (salaryFrom < 8000){
        alert("Нельзя людям так мало платить, жмот");
        document.getElementById('salaryRateFrom').value = 8000;
        salaryFrom = 8000;
        console.log("3");
    }

    if (salaryFrom > 10000000){
        alert("Вы слишком щедры со своими работниками");
        document.getElementById('salaryRateFrom').value = 8000;
        salaryFrom = 8000;
        console.log("4");
    }

    if (salaryUnder > 10000000){
        alert("Вы слишком щедры со своими работниками");
        document.getElementById('salaryRateUnder').value = 10000000;
        salaryUnder = 10000000;
        console.log("5");
    }

    if (Math.abs (salaryFrom - salaryUnder) < 1000){
        salaryUnder = salaryFrom + 2000;
        document.getElementById('salaryRateUnder').value = salaryUnder;
        console.log("6");
    }

    var salaryMinSlider = $( "#slider-salary" ).slider("option", "min");
    var salaryMaxSlider = $( "#slider-salary" ).slider("option", "max");

    if (salaryFrom < salaryMinSlider){
    salaryMinSlider = salaryFrom; 
    console.log(7);
    }

    if (salaryFrom > salaryUnder){
        var x = salaryFrom;
        salaryFrom = salaryUnder;
        salaryUnder = x;
    }



    console.log("salaryUnder" + salaryUnder);
    console.log("salaryMaxSlider" + salaryMaxSlider);
    if (salaryUnder > salaryMaxSlider){
    salaryMaxSlider = salaryUnder; 
    console.log(8);
    }

    $( "#slider-salary" ).slider("destroy");
    $( "#slider-salary" ).slider({
        range: true,
        min: salaryMinSlider,
        max: salaryMaxSlider,
        values: [ salaryFrom, salaryUnder],
        step : 1000,
        slide: function( event, ui ) {
            handlerSalarySlider( event,ui);
        }
    });
}

function updateSalaryFrom() {
    var salaryFrom = document.getElementById('salaryRateFrom').value;
    var salaryUnder = document.getElementById('salaryRateUnder').value;
}

function handlerSalarySlider(event, ui){
    
    var salaryFrom = $( "#slider-salary" ).slider( "values", 0 );
    var salaryUnder = $( "#slider-salary" ).slider( "values", 1 );

    document.getElementById("salaryRateFrom").value = salaryFrom;
    document.getElementById("salaryRateUnder").value = salaryUnder;
}



//******************************************************************************

/*
*
*
*/
function updateAge(fromPage) {

    var flagError = false;
    var ageFrom = document.getElementById('ageRateFrom').value;
    var ageUnder = document.getElementById('ageRateUnder').value;
    console.log("1");


    ageFrom = parseInt(ageFrom);
    ageUnder = parseInt(ageUnder);
    console.log("2");

    //если указанная зп меньше 8000
    if (ageFrom < 16){
        alert("Нельзя малолеток брать на работу");
        document.getElementById('ageRateFrom').value = 16;
        ageFrom = 16;
        console.log("3");
    }

    if (ageFrom > 100){
        alert("Не стоит брать столь старых работников к себе на работу");
        document.getElementById('ageRateFrom').value = 100;
        ageFrom = 18;
        console.log("4");
    }

    if (ageUnder > 100){
        alert("Не стоит брать столь старых работников к себе на работу");
        document.getElementById('ageRateUnder').value = 100;
        ageUnder = 100;
        console.log("5");
    }

    if (Math.abs (ageFrom - ageUnder) < 1){
        ageUnder = ageFrom + 2;
        document.getElementById('ageRateUnder').value = ageUnder;
        console.log("6");
    }

    var ageMinSlider = $( "#slider-age" ).slider("option", "min");
    var ageMaxSlider = $( "#slider-age" ).slider("option", "max");

    if (ageFrom < ageMinSlider){
        ageMinSlider = ageFrom; 
        console.log(7);
    }

    if (ageFrom > ageUnder){
        var x = ageFrom;
        ageFrom = ageUnder;
        ageUnder = x;
    }



    console.log("ageUnder" + ageUnder);
    console.log("ageMaxSlider" + ageMaxSlider);
    if (ageUnder > ageMaxSlider){
    ageMaxSlider = ageUnder; 
    console.log(8);
    }

    $( "#slider-age" ).slider("destroy");
    $( "#slider-age" ).slider({
        range: true,
        min: ageMinSlider,
        max: ageMaxSlider,
        values: [ ageFrom, ageUnder],
        step : 1,
        slide: function( event, ui ) {
            handlerAgeSlider( event,ui);
        }
    });
}

function updateAgeFrom() {
    var ageFrom = document.getElementById('ageRateFrom').value;
    var ageUnder = document.getElementById('ageRateUnder').value;
}

function handlerAgeSlider (event, ui){
    
    var ageFrom = $( "#slider-age" ).slider( "values", 0 );
    var ageUnder = $( "#slider-age" ).slider( "values", 1 );

    document.getElementById("ageRateFrom").value = ageFrom;
    document.getElementById("ageRateUnder").value = ageUnder;
}



//опыт работы
//******************************************************************************

/*
*
*
*/
function updateExperience(fromPage) {

    var flagError = false;
    var experienceFrom = document.getElementById('experienceRateFrom').value;
    
    if (experienceFrom == 'undefind'){
        flagError = true;
        alert("asd");
    }
        
    console.log("1");

    experienceFrom = parseInt(experienceFrom);
    
    console.log("2");
    
    //если указанная зп меньше 8000
    if (experienceFrom < 0 && !flagError){
        alert("???");
        document.getElementById('experienceRateFrom').value = 0;
        experienceFrom = 0;
        console.log("3");
    }

    if (experienceFrom > 20 && !flagError){
        alert("слишком опытный");
        document.getElementById('experienceRateFrom').value = 20;
        experienceFrom = 18;

    }

    var experienceMinSlider = $( "#slider-experience" ).slider("option", "min");
    var experienceMaxSlider = $( "#slider-experience" ).slider("option", "max");

    if (experienceFrom < experienceMinSlider && !flagError){
        experienceMinSlider = experienceFrom; 

    }

    
    console.log("experienceFrom" + experienceMaxSlider);
    console.log("experienceMinSlider" + experienceMaxSlider);
    console.log("experienceMaxSlider" + experienceMaxSlider);

    if (!flagError){
        $( "#slider-experience" ).slider("destroy");
        $( "#slider-experience" ).slider({
            min: experienceMinSlider,
            max: experienceMaxSlider,
            values: [ experienceFrom ],
            step : 1,
            slide: function( event, ui ) {
                handlerExperienceSlider( event,ui);
            }
        });
    }
}

function updateExperienceFrom () {
    var experienceFrom = document.getElementById('experienceRateFrom').value;
}

function handlerExperienceSlider (event, ui){
    
    var experienceFrom = $( "#slider-experience" ).slider( "values", 0 );

    document.getElementById("experienceRateFrom").value = experienceFrom;
}

function getParticipants(){
    var idFirm = document.getElementById("branch").value;
    
    var  dataSend = {
                 query: 'getListPostParticipants',
                 idFirm : idFirm
        }
        
        $.post(
            W_AJAX + "controllers/controllerCompany.php",
            {
                dataSend : dataSend
            },
            function(data){
                var serverAnswer = data;
                    $('#contactUser').innerHTML='';
                    document.getElementById('contactUser').innerHTML = serverAnswer;
                },
            'text'
        ); 
}

//*****************************************************************************

function tideVacancy(){
    
    var text = document.getElementById("name").value;
    if (text == "Название вакансии"){
        document.getElementById("name").value='';
    }  
}

function recoverVacancy(){
    
    var text = document.getElementById("name").value;
    if (text == ""){
        document.getElementById("name").value='Название вакансии';
    }  
}

//**
function tideContactPerson(){
    var text = document.getElementById("contactInfo").value;
    if (text == "Контактная персона"){
        document.getElementById("contactInfo").value='';
    }  
}

function recoverContactPerson(){
    var text = document.getElementById("contactInfo").value;
    if (text == ""){
        document.getElementById("contactInfo").value='Контактная персона';
    }  
}


/*
 *JS функция аналогичная PHP trim
 *@param string s - входная строка
 *@return string - выходная отформотированная строка
 **/
function TrimStr(s) {
  if (typeof s != "undefined"){
    s = s.replace( /^\s+/g, '');
    return s.replace( /\s+$/g, '');
  }
  else{
      return '';
  }
} 



/*
 *При невведенном значении города, надпись "введите город" исчезает
 *@return void;
 **/
function inputSpecializationFocus(){
   
   var country = document.getElementById('vacancySpeciality').value; 
   
   if (country == 'специальность')
       document.getElementById('vacancySpeciality').value = ''; 
}

/*
 *При пустом значении в инпуте  города, это пустое значение меняется на надпись "введите город"
 *@return void;
 **/
function inputSpecializationBlur(){
   
   var country = document.getElementById('vacancySpeciality').value; 
   
   if (country == '')
       document.getElementById('vacancySpeciality').value = 'специальность';
}

/*
 *При невведенном значении города, надпись "введите город" исчезает
 *@return void;
 **/
function inputCityFocus(){
   
   var country = document.getElementById('city').value; 
   
   if (country == 'введите город')
       document.getElementById('city').value = ''; 
}

/*
 *При пустом значении в инпуте  города, это пустое значение меняется на надпись "введите город"
 *@return void;
 **/
function inputCityBlur(){
   
   var country = document.getElementById('city').value; 
   
   if (country == '')
       document.getElementById('city').value = 'введите город';
}
